import Vue from "vue";

import App from "./App.vue";
import VueRouter from "vue-router";

import Home from "./views/Home.vue";
import Cart from "./views/Cart.vue";
import Shop from "./views/Shop.vue";
import NotFound from "./views/NotFound.vue";

/*
  1. 注册了组件 router-link 和 router-view
  2. 通过根配置项router，给所有的vue组件注入了对象$route和$router
  */
Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    {
      path: "/home",
      component: Home,
      children: [
        {
          // 嵌套路由路径前不能加 /
          //  /home/shop
          path: "shop",
          component: Shop,
        },
        {
          //  /home/cart
          path: "cart",
          component: Cart,
        },
      ],
    },
  ],
});

new Vue({
  el: "#app",
  router,
  render: (h) => h(App),
});
